﻿using Microsoft.Extensions.DependencyInjection;
using Quartz.Impl.AdoJobStore.Common;
using System;
using WalkingTec.Mvvm.Core;

namespace Digitalmes.Services
{
    public class BaseService : IDisposable
    {
        private readonly IServiceProvider _provider;
        private readonly object _scopeLock = new object();
        private IServiceScope _scope;
        private bool _disposed = false;

        public BaseService()
        {

        }

        public BaseService(IServiceProvider serviceProvider)
        {
          
        }

       


        public IDataContext DC => Wtm.DC;
       

        public WTMContext Wtm => GetService<WTMContext>();
        public ILogService Log => GetService<ILogService>();

        protected T GetService<T>()
        {
            return ServiceLocator.Current.GetService<T>();
            //return Scope.ServiceProvider.GetRequiredService<T>();
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    _scope?.Dispose();
                }
                _disposed = true;
            }
        }
    }
}
